package com.sk.sk_frame_cloud.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sk.sk_frame_cloud.config.DynamicDataSourceHolder;
import com.sk.sk_frame_cloud.constants.CommonConstant;
import com.sk.sk_frame_cloud.entity.Functions;
import com.sk.sk_frame_cloud.entity.SysProFunInfo;
import com.sk.sk_frame_cloud.mapper.FunctionsMapper;
import com.sk.sk_frame_cloud.param.SysFunctionParam;
import com.sk.sk_frame_cloud.res.CommonResponse;
import com.sk.sk_frame_cloud.service.IFunctionsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sk.sk_frame_cloud.service.ISysProFunInfoService;
import com.sk.sk_frame_cloud.service.ISysProFunRelationService;
import com.sk.sk_frame_cloud.service.ISysProManageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiaok
 * @since 2023-12-19
 */
@Service
public class FunctionsServiceImpl extends ServiceImpl<FunctionsMapper, Functions> implements IFunctionsService {


    @Override
    public void operaFollowFunction(String dbCode, SysFunctionParam functionParam) {
        //切换数据库
        DynamicDataSourceHolder.setDynamicDataSourceKey(dbCode);

        Functions functions = new Functions();
        functions.setCode(functionParam.getCode());
        functions.setNickname(functionParam.getNickname());
        functions.setType(functionParam.getFunType());
        functions.setCreateTime(LocalDateTime.now());
        functions.setUpdateTime(LocalDateTime.now());
        this.save(functions);

        // TODO: 2023-12-20 操作子项目的权限表，但是这里两个项目这部分内容是一致的，所以直接调用user服务的中的方法即可，稍后通过fegin完善 
        
    }

    @Override
    public void removeFollowFunctionAndPermission(String dbCode, SysFunctionParam functionParam) {
        //切换数据源
        DynamicDataSourceHolder.setDynamicDataSourceKey(dbCode);

        //移除功能表
        this.remove(new QueryWrapper<Functions>().eq("code",functionParam.getCode()));

        //移除权限表
        // TODO: 2023-12-20

    }
}
